package com.ideaplugin.datamanager.controller;

import com.ideaplugin.datamanager.model.common.ListResult;
import com.ideaplugin.datamanager.model.common.PageRequest;
import com.ideaplugin.datamanager.model.common.PageResult;
import com.ideaplugin.datamanager.model.common.PlainResult;
import com.ideaplugin.datamanager.model.request.ListTablesBySchemaNameParam;
import com.ideaplugin.datamanager.model.request.TableInfoParam;
import com.ideaplugin.datamanager.model.response.DataSourceInfoVo;
import com.ideaplugin.datamanager.model.response.SchemaTableInfoVo;
import com.ideaplugin.datamanager.model.response.TableInfoVo;
import com.ideaplugin.datamanager.service.TableInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhaojingbo
 * @since 2023-06-07
 */
@RestController
@RequestMapping("/tableInfo")
public class TableInfoController {

    @Autowired
    private TableInfoService tableInfoService;


    @GetMapping("/delete")
    public PlainResult<Boolean> delete(Long param) {
        return new PlainResult<>(tableInfoService.delete(param));

    }

    @GetMapping("/listSchemaByDataSource")
    public ListResult<String> listSchemaByDataSource(String param) {
        return new ListResult<>(tableInfoService.listSchemaByDataSource(param));

    }

    @PostMapping("/listTablesBySchemaName")
    public ListResult<SchemaTableInfoVo> listTablesBySchemaName(@RequestBody ListTablesBySchemaNameParam param) {
        return new ListResult<>(tableInfoService.listTablesBySchemaName(param));

    }

    //@PostMapping("/importByTableName")
    //public PlainResult<Boolean> importByTableName(@RequestBody ImportByTableNameParam param) {
    //    return new PlainResult<>(tableInfoService.importByTableName(param));
    //
    //}

    @PostMapping("/saveOrUpdate")
    public PlainResult<Boolean> saveOrUpdate(@RequestBody TableInfoParam param) {
        return new PlainResult<>(tableInfoService.saveOrUpdate(param));

    }

    @PostMapping("/page")
    public PageResult<TableInfoVo> page(@RequestBody PageRequest<TableInfoParam> param) {
        return tableInfoService.page(param);

    }

    @GetMapping("/listDataSource")
    public ListResult<DataSourceInfoVo> listDataSource() {
        return new ListResult<>(tableInfoService.listDataSource());

    }


    @GetMapping("/getById")
    public PlainResult<TableInfoVo> getById(@RequestParam Long id) {
        return new PlainResult<>(tableInfoService.getById(id));
    }


}
